package com.newvpn.fastbest.zenith.utils;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.best.smart.center.CenterLog;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.newvpn.fastbest.zenith.BuildConfig;

import java.util.Map;

import ly.count.android.sdk.Countly;
import ly.count.android.sdk.CountlyConfig;

public class VLog {

    private static Countly mCountly;
    private static FirebaseAnalytics mFirebaseAnalytics;
    private static AppEventsLogger fbLogger;

    public static void init(Context context){
        mFirebaseAnalytics = FirebaseAnalytics.getInstance(context);
        FacebookSdk.sdkInitialize(context);
        mCountly = Countly.sharedInstance().init(new CountlyConfig(context, BuildConfig.COUNTLY_KEY, BuildConfig.COUNTLY_URL));
        mCountly.setLoggingEnabled(true);
        fbLogger = AppEventsLogger.newLogger(context);
    }

    public static void event(String event){
        try {
           // CenterLog.log(event);
            CenterLog.logEvent(event);
            mCountly.events().recordEvent(event);
            Bundle bundle = new Bundle();
            mFirebaseAnalytics.logEvent(event,bundle);
            fbLogger.logEvent(event);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void event(String event, Map<String, Object> map) {
        try {
            //CenterLog.log(event+","+map.toString());
            CenterLog.logEvent(event+","+map.toString());
            mCountly.events().recordEvent(event,map);
            Bundle bundle = new Bundle();
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                String k = entry.getKey();
                Object value = entry.getValue();
                bundle.putString(k,  value.toString());
            }
            mFirebaseAnalytics.logEvent(event,bundle);
            fbLogger.logEvent(event,bundle);
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    public static void e(String info){
        if (BuildConfig.OPENLOG){
            Log.e("NewVPN1",info);
            CenterLog.log(info);
        }
    }


}
